<template>
  <div class="h100" ref="projectTableList">
    <s-table ref="table" class="h100" :rowKey="record => record.id" :columns="columns" :data="loadData"
      @getPagination="getPagination">
      <template slot-scope="text" v-for="column in commonColumns" :slot="column.scopedSlots.customRender">
        <table-ellipsis :text="text || '-'" :key="column.dataIndex"></table-ellipsis>
      </template>
      <template slot="responseTime" slot-scope="text">
        <table-ellipsis :text="text + 'ms'"></table-ellipsis>
      </template>
      <template slot="createTime" slot-scope="text">
        <table-ellipsis :text="$commonFun.getDateTimeStr(text)"></table-ellipsis>
      </template>
      <template slot="exception" slot-scope="text">
        <table-ellipsis :text="$t(text ? 'unnormal' : 'normal')"></table-ellipsis>
      </template>
      <template slot="action" slot-scope="text,record">
        <auth-text :auth="managePerms.project.edit" @click="doAction('editProject', record)">{{ $t('edit') }}</auth-text>
      </template>
    </s-table>
  </div>
</template>
<script>
import sysLogApi from '@/api/modules/system/log'
import { STable } from '@/components'
import AuthText from '@/components/AuthText'
import tableEllipsis from '@/components/Ellipsis/TableEllipsis'
import { managePerms } from '@/config/permission/index'
import { mapState } from 'vuex'
import { sysLogTbColumns } from '../config/list'
export default {
  components: {
    tableEllipsis,
    STable,
    AuthText
  },
  computed: {
    ...mapState({
      queryParams: (state) => state.sysLog.queryParams,
      order: (state) => state.sysLog.order
    }),
    commonColumns() {
      return this.columns.filter(item => !item.special)
    }
  },
  data() {
    return {
      columns: sysLogTbColumns,
      managePerms
    }
  },
  watch: {
  },
  created() {
  },
  mounted() {
  },
  methods: {
    loadData(parameter) {
      this.$store.commit('setOrder', parameter.order)
      const params = { ...parameter, ...this.queryParams }
      // if (params.startTime) {
      //   params.startTime = params.startTime + ':00'
      // }
      // if (params.endTime) {
      //   params.endTime = params.endTime + ':00'
      // }
      return sysLogApi.getSysLogPageData(params)
    },
    doAction(key, rowData) {
      if (this[key]) {
        this[key](rowData)
        return
      }
      this.$emit('clickbtn', { type: key, data: rowData })
    },
    getPagination() {

    },
    refreshData(isToFirstPage = true) {
      const vm = this
      vm.$nextTick(() => {
        vm.$refs.table.refresh(isToFirstPage)
      })
    }
  }
}
</script>
<style lang="less" scoped></style>
